13 int cap
[MAXN
+1][MAXN
+1], flow
[MAXN
+1][MAXN
+1], prev
[MAXN
+1];
15 int fordFulkerson(int n
, int s
, int t
){
17 for (int i
=0; i
<n
; ++i
) fill(flow
[i
], flow
[i
]+n
, 0);
19 fill(prev
, prev
+n
, -1);
22 while (q
.size() && prev
[t
] == -1){
25 for (int v
= 0; v
<n
; ++v
)
26 if (v
!= s
&& prev
[v
] == -1 && cap
[u
][v
] > 0 && cap
[u
][v
] - flow
[u
][v
] > 0)
27 prev
[v
] = u
, q
.push(v
);
30 if (prev
[t
] == -1) break;
32 int bottleneck
= INT_MAX
;
33 for (int v
= t
, u
= prev
[v
]; u
!= -1; v
= u
, u
= prev
[v
]){
34 bottleneck
= min(bottleneck
, cap
[u
][v
] - flow
[u
][v
]);
36 for (int v
= t
, u
= prev
[v
]; u
!= -1; v
= u
, u
= prev
[v
]){
37 flow
[u
][v
] += bottleneck
;
38 flow
[v
][u
] = -flow
[u
][v
];
47 while (scanf("%d", &n
) == 1 && n
){
48 for (int i
=0; i
<n
; ++i
){
49 fill(cap
[i
], cap
[i
]+n
, 0);
52 scanf("%d %d %d", &s
, &t
, &C
);
56 scanf("%d %d %d", &i
, &j
, &k
);
57 cap
[--i
][--j
] += k
, cap
[j
][i
] += k
;
60 printf("Network %d\nThe bandwidth is %d.\n\n", runs
++, fordFulkerson(n
, s
, t
));